package com.yllt4cloud.ddauth.service.impl;

import com.yllt4cloud.common.core.util.ResultResp;
import com.yllt4cloud.common.ddbase.constant.ClerkConstants;
import com.yllt4cloud.common.ddbase.constant.ErrorCode;
import com.yllt4cloud.common.ddbase.constant.entity.ServiceException;
import com.yllt4cloud.common.ddbase.domain.Clerk;
import com.yllt4cloud.common.ddbase.result.ClerkResult;
import com.yllt4cloud.common.ddbase.result.ClerkZhiWen;
import com.yllt4cloud.ddauth.mapper.ClerkMapper;
import com.yllt4cloud.ddauth.service.IClerkService;
import com.yllt4cloud.ddauth.service.base.BaseService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 *
 * <br>
 * <b>功能：</b>ClerkServiceImpl<br>
 * <b>作者：</b>Administrator<br>
 * <b>日期：</b> Tue Feb 12 10:53:44 CST 2019 <br>
 * <b>版权所有： 2016,yllt.com<br>
 */
@Service
@Transactional
public class ClerkServiceImpl extends BaseService<Clerk> implements IClerkService {
	private final static Logger log= LoggerFactory.getLogger(ClerkServiceImpl.class);

	@Autowired
    private ClerkMapper mapper;

	public ClerkMapper getMapper() {
		return mapper;
	}

	@Override
	public Integer insert(Clerk record) {
		mapper.insert(record);
		return record.getId();
	}


	@Override
	public Clerk cardGetClerk(String clerkCardNum) {
		List<Clerk> cardGetClerks = getMapper().cardGetClerk(clerkCardNum);
		if (CollectionUtils.isEmpty(cardGetClerks)) {
			return null;
		}
        Clerk clerk = cardGetClerks.get(0);
		if (Integer.valueOf(ClerkConstants.CLERK_STATUS_DISABLE).equals(clerk.getStatus())) {
            throw new ServiceException(ResultResp.fail("人员已离职", ErrorCode.JSON_PARSE_ERROR));
        }
		return clerk;
	}


    /**
     * 查询花名册列表
     * @param paramMap
     * @return
     */
    public List<ClerkResult> queryHuaMingCeList(Map<String, Object> paramMap){

        return getMapper().queryHuaMingCeList(paramMap);

    }

	@Override
	public List<Integer> queryIdsByIds(Map<String, Object> paramMap) {
		return getMapper().idQueryByIds(paramMap);
	}

	@Override
	public List<Clerk> queryByIds(Map<String, Object> paramMap) {
		return getMapper().queryByIds(paramMap);
	}

	@Override
	public List<ClerkZhiWen> listZhiWen() {
		return getMapper().listZhiWen();
	}

}
